package com.hy.dao;

import com.hy.bean.Accusation;
import com.hy.bean.Discuss;
import com.hy.utils.DBManager;
import com.hy.utils.DateUtil;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

public class ReportDao {
    private QueryRunner qr = new QueryRunner();

    public List<Map<String,Object>> selectReport() throws Exception {
        Connection conn = DBManager.getConn();
        String sql = "select * from report";

        List<Map<String, Object>> query = qr.query(conn, sql, new MapListHandler());

        DbUtils.close(conn);
        return query;
    }
    public boolean insertAccusation(Accusation accusation) throws Exception {
        Connection conn = DBManager.getConn();

        String sql = "INSERT INTO accusation VALUES (null, ?, ?, ?, ?,?, ?, null, ?, null, '0', '0');";
        int count = qr.update(conn, sql,accusation.getCardId(),accusation.getUserId(),accusation.getCommentId(),accusation.getReportId(),accusation.getContent(),DateUtil.datetime(),accusation.getCreateId());
        DbUtils.close(conn);

        return count > 0 ? true : false;
    }
}